package com.baizhi.cmfzdemo.controller;

import com.baizhi.cmfzdemo.service.CmfzUserService;
import com.baizhi.cmfzdemo.service.UserThreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 用户控制层
 * Created by 54433 on 2019/4/3.
 */
@Controller
@RequestMapping("/user")
public class CmfzUserController {
    //封装service
    @Autowired
    private CmfzUserService cmfzUserService;
    @Autowired
    private UserThreadService userThreadService;

    @RequestMapping("/queryAllUser")
    @ResponseBody
    public Map queryAllUser(int page,int rows){
        System.out.println(page+"&*&*&*&*&**"+rows);
        System.out.println(cmfzUserService.queryAllUser(page,rows));
        cmfzUserService.queryAllUser(page,rows);
        return cmfzUserService.queryAllUser(page,rows);
    }

    @RequestMapping("/getSexCount")
    @ResponseBody
    public List<Map> queryBySex(){
        return cmfzUserService.queryBySex();
    }

    @RequestMapping("/getByProvince")
    @ResponseBody
    public List<Map> queryByProvince(){
        return cmfzUserService.queryByProvince();
    }
    @RequestMapping("/getByDayCount")
    @ResponseBody
    public Map getByDayCount(){
        return cmfzUserService.selectByDayCount();
    }

    /**
     *  优化
     * @return
     * @throws InterruptedException
     */
    @RequestMapping("/selectAllCountThread")
    @ResponseBody
    public Map selectAllCountThread() throws Exception {
        long start = System.currentTimeMillis();
        Map map = userThreadService.selectAllCountFuture();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms");
        return map;
    }

    /**
     * 无优化
     */
    @RequestMapping("/selectAllCount")
    @ResponseBody
    public Map selectAllCount() {
        long start = System.currentTimeMillis();

        Map map = userThreadService.selectAllCount();
        long end = System.currentTimeMillis();
        System.out.println(end-start+"ms");
        return map;
    }

}
